package com.zzti.serviceImpl;


import com.zzti.mapper.OrderGoodsMapper;
import com.zzti.pojo.OrderGoods;
import com.zzti.service.OrderGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class OrderGoodsServiceImpl implements OrderGoodsService {
    @Autowired
    private OrderGoodsMapper orderGoodsMapper;

    @Override
    public Integer add(Integer visiterId, Integer goodsId, Integer number, Double price, String address) {
        OrderGoods og = new OrderGoods();
        og.setVisiterId(visiterId);
        og.setNumber(number);
        og.setPrice(price);
        og.setTotal(number * price);
        og.setGoodsId(goodsId);
        Date date = new Date();
        og.setCreateTime(date);
        if (address != null && !"".equals(address))
            og.setAddress(address);
        System.out.println(og.toString());
        return orderGoodsMapper.insert(og);
    }

    @Override
    public List<OrderGoods> selectList(Map map) {
        return orderGoodsMapper.selectList(map);
    }

    @Override
    public Integer deleteByIds(Integer[] ids) {
        List<Integer> lids = Arrays.asList(ids);
        return orderGoodsMapper.deleteBatchIds(lids);

    }

}
